<?
listProducts();
function listProducts(){
	global $db,$template,$cid;
	$sql="select proID,Keywords  from vb_products where proActive=1 and  memID=".$cid." group by Keywords order by Keywords" ;
	
	if(!$result=$db->sql_query($sql)){
	  message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
	}
	$prod_count=$db->sql_numrows($result);
	$prod_data=$db->sql_fetchrowset($result);
 
	 for($i=0;$i<$prod_count;$i++){
		$template->assign_block_vars("promenuRow", array(							
		'url'	 => 'supplier.php?supplier='.$cid."&act=products&catID=".$prod_data[$i]["proID"],
		'proCatName'	 =>	$prod_data[$i]["Keywords"],
		'proCount'		 =>	getNumpro($prod_data[$i]["Keywords"]),
			));
	}
			
	$template->set_filenames(array(
		"lefmenu"	=> "template/prolist.tpl"
	));
	$template->pparse('lefmenu');
	unset($prod_data);
	$template->destroy();	
}
function getNumpro($keywords=''){
 global $db,$cid,$catID; 
 $sql="select  proID,ProductName,Keywords from vb_products where proActive=1 and memID=".$cid;
	if(!$result=$db->sql_query($sql)){
	  message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
	}
	$pro_count=$db->sql_numrows($result);
	$pro_data=$db->sql_fetchrowset($result);	
	if($catID){
		for($i=0;$i<$pro_count;$i++){
			if($pro_data[$i]["proID"]==$catID){
			$keyw=$pro_data[$i]["Keywords"];
				break;
		}
 }
	}
	
 $cSell=0;
	$sql= "select datepost,Effective,lID from vb_sell_lead where  active=1 and memID=".$cid;
	if(!$result=$db->sql_query($sql)){
	  message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
	}
	$sqlCommon =' (lID=-1' ;
	$sel_count=$db->sql_numrows($result);
	$sel_data=$db->sql_fetchrowset($result);	
		for($i=0;$i<$sel_count;$i++){
			 $expridate=getExpried($sel_data[$i]["Effective"],$sel_data[$i]["datepost"]);	 
			
			 if(date($expridate)>date('Y-m-d',time())){
			 	$cSell=$cSell+1;
				$sqlCommon.=' or lID='.$sel_data[$i]['lID'] ; 
			 }
 		}

$expir=$db->getRecord("select expired from vb_member where memID=".$cid);
if($expir){
	redirect('index.php');
}

  $proCount=0;
   for($i=0;$i<$pro_count;$i++){
 	if($pro_data[$i]["Keywords"]==$keywords){
 	$proCount=$proCount+1;
	}
 }
 
 return $proCount;
}
?>